/* © 2007 Adobe Systems Incorporated. All rights reserved. */
package com.shubhjai.musiclib.data.parsers
{
	import flash.events.EventDispatcher;
	import com.shubhjai.musiclib.commands.Command;
	import com.shubhjai.musiclib.model.Record;
	
	/**
	 * This class parses a particular CSV data format:
	 * 
	 * firstName,lastName,id,title,managerId,department,location,phone,phoneExtension
	 */
	public class RecordCSVParser implements IDataParser
	{
		
		/** 
		 * Parse the given line delimited CSV data. 
		 * 
		 * @param data The data object that will be parsed. 
		 * @return An array of Record objects.
		 */
		public function parse( data:Object ) : Array
		{
			var results : Array = new Array();
			
			var entries : Array = String( data ).split("\n");
			var employee : Record;
			var itemArr : Array
			
			for each ( var entry:String in entries )
			{
				itemArr = entry.split(",");
				employee = new Record();
		
				employee.firstName = itemArr[0];
				employee.lastName = itemArr[1];
				employee.displayName = itemArr[0] + " " + itemArr[1];
				employee.id = itemArr[2];
				employee.email = itemArr[2] + "@samplecorp.com";
				employee.title = itemArr[3];
				employee.managerId = itemArr[4];
				employee.department = itemArr[5];
				employee.city = itemArr[6];
				employee.state = itemArr[7];
				employee.phone = itemArr[8];
				employee.phoneExtension = itemArr[9];
			
				results.push( employee );
			}
			
			return results;
			
		}
	}
}